import * as reportPlanService from '../../services/report/reportPlan';

import moment from 'moment'

export default {
  namespace: 'reportList',
  state: {
    list: [], 
    current : 1,
    currentSize : 10,
    total : 0, 
    newKey :'',
  },
  reducers: {    
    upState(state, { payload}) {
      return { ...state, ...payload };
    },
   
  },
  effects: {       
    *queryList({ payload },{ call, put }) {
      const { body } = yield call(reportPlanService.queryReportFileList,payload);
      yield put({ type: 'upState', payload: { list:body.data, current:body.current, currentSize:body.size, total:body.iTotalRecords}});
    }, 
    *remove({ payload ,search},{ call, put }){
      const { body } = yield call(reportPlanService.removeFile,payload);
      yield put({ type: 'queryList', payload:search});
    },  
    *downLoadFile({ payload },{ call, put }){
      const { body } = yield call(reportPlanService.downLoadFile,payload);
    },  
     
  },
  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname }) => {
        if (pathname === '/reportList') {
          dispatch({ type: 'queryList', payload:{ 'fileName':'' }});
         
        }
      });
    },
  },
};
